//
//  ALPS_MainListenCollectionViewCell.m
//  Alps
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_MainListenCollectionViewCell.h"

@implementation ALPS_MainListenCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
         self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, ScreeHeight / 6.67 - 20, ScreeHeight / 6.67 - 20)];
        [self.contentView addSubview:_leftImageView];
        
        self.finishImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _leftImageView.frame.size.width / 2, _leftImageView.frame.size.height / 2)];
        [self.leftImageView addSubview:_finishImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(0, ScreeHeight / 6.67, ScreeHeight / 6.67 - 40, 40));
        }];
        
        self.introLabel = [[UILabel alloc] init];
        self.introLabel.font = [UIFont systemFontOfSize:14];
        self.introLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_introLabel];
        [self.introLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 16.675, ScreeHeight / 6.67, ScreeHeight / 6.67 - ScreeHeight / 11.17, 40));
        }];
        
        self.playImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_playImageView];
        [self.playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 25, ScreeHeight / 6.67, 10, ScreeWidth - ScreeHeight / 6.67 - 15));
        }];
        
        self.playCountLabel = [[UILabel alloc] init];
        self.playCountLabel.font = [UIFont systemFontOfSize:14];
        self.playCountLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_playCountLabel];
        [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 30, ScreeHeight / 6.67 + 15, 5, ScreeWidth / 1.97));
        }];
        
        self.numberImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_numberImageView];
        [self.numberImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 25, ScreeWidth / 1.97, 10, ScreeWidth - ScreeWidth / 1.83));
        }];
        
        self.numberLabel = [[UILabel alloc] init];
        self.numberLabel.textColor = [UIColor grayColor];
        self.numberLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_numberLabel];
        [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 30, ScreeWidth / 1.83, 5, 100));
        }];

    }
    return self;
}

- (void)setModel:(ALPS_MainModel *)model
{
    if (_model != model) {
        _model = model;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.coverPath]];
        self.titleLabel.text = model.title;
        self.introLabel.text = model.subtitle;
        self.playImageView.image = [UIImage imageNamed:@"find_specialicon"];
        self.playCountLabel.text = model.footnote;
    }
}

- (void)setMoreModel:(ALPS_MoreModel *)moreModel
{
    if (_moreModel != moreModel) {
        _moreModel = moreModel;
        [self.leftImageView  sd_setImageWithURL:[NSURL URLWithString:moreModel.coverMiddle] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
        self.titleLabel.text = moreModel.title;
        self.introLabel.text = moreModel.intro;
        
        if (moreModel.tracks != 0) {
            self.playImageView.image = [UIImage imageNamed:@"album_play"];
            self.numberImageView.image = [UIImage imageNamed:@"album_tracks"];
            self.numberLabel.text = [NSString stringWithFormat:@"%ld集", moreModel.tracks];
            if (moreModel.playsCounts > 10000) {
                self.playCountLabel.text = [NSString stringWithFormat:@"%.1f万", moreModel.playsCounts / 10000];
            } else {
                self.playCountLabel.text = [NSString stringWithFormat:@"%ld", (NSInteger)moreModel.playsCounts];
            }
        } else {
            self.playImageView.image = [UIImage imageNamed:@"find_specialicon"];
            self.playCountLabel.text = moreModel.footnote;
            self.introLabel.text = moreModel.subtitle;
            [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:moreModel.coverPathSmall]];
        }
        
        if (moreModel.isFinished == 2) {
            self.finishImageView.image = [UIImage imageNamed:@"album_novel_finish"];
        }
    }
}

@end
